﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Stamp_For_Africa_Version_2.Models;
using Stamp_For_Africa_Version_2.Repositories;

namespace Stamp_For_Africa_Version_2.Controllers
{
	public class PaperController : Controller
	{
		private readonly PaperRepository _paperRepository = new PaperRepository();
		//
		// GET: /Paper/

		public ActionResult Index()
		{
			List<Paper> papers = _paperRepository.FindAllPapers().ToList();
			return View(papers);
		}

		[Authorize]
		public ActionResult Create()
		{
			Paper paper = new Paper();
			return View(paper);
		}

		[Authorize]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Create(Paper paper)
		{
			paper.Id = Guid.NewGuid();
			_paperRepository.Add(paper);
			return View("Details", paper);
		}

		public ActionResult Details(Guid id)
		{
			Paper paper = _paperRepository.GetPaper(id);
			return View(paper);
		}

		[Authorize]
		public ActionResult Edit(Guid id)
		{
			Paper paper = _paperRepository.GetPaper(id);
			return View(paper);
		}
		
		[Authorize]
		public ActionResult Edit(Guid id, FormCollection formCollection)
		{
			Paper paper = _paperRepository.GetPaper(id);
			if (paper != null)
			{
				UpdateModel(paper);
			}
			return View("Details", paper);
		}

		[Authorize]		
		public ActionResult Delete(Guid id)
		{
			_paperRepository.Delete(id);
			return RedirectToAction("Index");
		}

	}
}
